//  File:         Entry.cpp
//  Author:       Scott Nordmann & Lauren Wallace
//  Description:  Non-inline member function definitions.
#include "Entry.h"
#include <string>
#include <iostream>

using namespace std;
//entry creation
Entry::Entry(const string& creator)
{
	setCreatorName(creator);
	setTitle(".Untitled");
	setContent(".No content");
}
Entry::Entry(const string& creator,const string& titl, const string& cont)
{
	setCreatorName(creator);
	setTitle(titl);
	setContent(cont);
}

Entry::~Entry()
{
    vector<Tag*>::iterator iter;
    for(iter=tags.begin(); iter != tags.end(); ++iter)
    {
		(*iter)->removeFromTagSpec();
        delete *iter;
    }
}

void Entry::populate()
{
	string input;

	// this doesn't work. it skipps title entry. its probably grabbing a return
	// it has to be this way, plain cin cuts off at spaces- put a cin.ignore() before you call it
	cout << "Title: ";
	getline(cin, input);
	setTitle(input);

	cout << "Content: ";
	getline(cin, input);
	setContent(input);
}


//tag
void Entry::tag(Tag& currentTag)
{
	currentTag.setEntry(*this);
	tags.push_back(&currentTag);
}
//display
void Entry::display() const
{
	cout << "Title: "   << getTitle()       << endl;
	cout << "Content: " << getContent()     << endl;
	cout << "Creator: " << getCreatorName() << endl;
}

void Entry::displayTitle() const
{
	cout << getTitle() << endl;
}

void Entry::displaySummary() const
{
	string shortCreatorName = getCreatorName();

	if (shortCreatorName.length() > 9)
	{
		shortCreatorName = shortCreatorName.substr(0, 6) + "...";
	}

	string shortTitle = getTitle();
	
	if (shortTitle.length() > 20)
	{
		shortTitle = shortTitle.substr(0, 17) + "...";
	}

	string contentSummary = getContent();
	
	if (contentSummary.length() > 35)
	{
		contentSummary = contentSummary.substr(0, 33) + "...";
	}

	cout << shortCreatorName << " - "
		 << shortTitle << ": "
		 << contentSummary << endl;
}

void Entry::displayTags() const
{
	TagSpec* currentTag;
	vector<Tag*>::const_iterator iter;
	for (iter=tags.begin();iter != tags.end(); ++iter)
	{
		currentTag = (*iter)->getSpec();
		currentTag->display();
	}
}



//access
void Entry::setTitle(const std::string& titl)
{	
	//validation goes here
	title = titl;
}

void Entry::setContent(const std::string& cont)
{	
	//validation goes here
	content = cont;
}

void Entry::setCreatorName(const std::string& crea)
{	
	//validation goes here
	creatorName = crea;
}

void Entry::setSendTo(const std::string& send)
{	
	//validation goes here
	sendTo = send;
}

